<script lang="ts" setup>
import useStore from '@/store';
import { useLazyData } from '@/utils/hooks';
import HomePanel from './HomePanel.vue';
const { home }  = useStore()

// const target = ref(null)
const target = useLazyData(()=>{
  home.getHotList()
})
// const target = ref(null)
// // 当整个区块处于可见状态时，才发ajax
// onMounted(() => {
//   const { stop } = useIntersectionObserver(target.value, ([{ isIntersecting }]) => {
//     console.log('新鲜好物', isIntersecting)
//     // 可见
//     if(isIntersecting) {
//       // 发请求
//       home.getHotList()

//       // 停止监听
//       stop()
//     }
//   })
// })
</script>
<template>
  <div ref="target">
  <HomePanel title="人气推荐" subTitle="人气爆款 不容错过">
    <!-- 面板内容 -->
    <ul class="goods-list">
      <li v-for="item in home.hotGoodList" :key="item.id">
        <RouterLink :to="'/product/'+item.id">
          <img
            v-lazy="item.picture"
            alt=""
          />
          <p class="name ellipsis">{{item.title}}</p>
          <p class="price">{{item.alt}}</p>
        </RouterLink>
      </li>
    </ul>
  </HomePanel>
  </div>
</template>

<style scoped lang="less">
.goods-list {
  display: flex;
  justify-content: space-between;
  height: 406px;
  li {
    width: 306px;
    height: 406px;
    background: #fff;
    .hoverShadow();
    img {
      width: 306px;
      height: 306px;
    }
    p {
      font-size: 22px;
      padding: 12px 30px 0 30px;
      text-align: center;
    }
    .price {
      font-size: 18px;
      color: #999;
    }
  }
}
</style>
